package com.lanmaoly.cunzheng.thread;

public class MethodAysnc implements Runnable {

    public static int i = 0;

    public static synchronized void increse() {
        for (int j = 1; j <= 10; j++) {
            System.out.println(Thread.currentThread().getName());
            i++;
        }
    }

    @Override
    public void run() {
        increse();
    }

    public static void main(String[] args) throws Exception {
        //两个线程使用各自的锁，线程不同步
        Thread t1 = new Thread(new MethodAysnc());
        Thread t2 = new Thread(new MethodAysnc());

        //两个线程公用同一把锁，线程同步
        /*MehodAsync m = new MehodAsync();
        Thread t1 =new Thread(m);
        Thread t2 =new Thread(m);*/

        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(i);
    }

}